package com.cityp.controller;

import com.cityp.bean.Manager;
import com.cityp.bean.ResultBean;
import com.cityp.bean.User;
import com.cityp.service.ManagerService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Manager")
public class ManagerController {

    @Autowired
    private ManagerService ManagerService;

    @GetMapping(value="/viewAll")
    @ResponseBody
    public ResultBean viewAll(){
        List<Manager> res=ManagerService.viewAll();
        if(res==null) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success("查询成功",res);
    }

    @PostMapping(value="/addOne")
    public ResultBean addOne(@RequestBody Manager Manager){
        int res=ManagerService.AddOne(Manager);
        if (res==0) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success("添加成功");
    }
    @PostMapping(value = "/changeOne")
    public ResultBean changeOne(@RequestBody Map<String,Object> para){
        int res=ManagerService.changeOne((String) para.get("id"),(String)para.get("para"));
        if (res==0) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success("修改成功");
    }

    @GetMapping(value="/viewUser")
    @ResponseBody
    public ResultBean viewUser(){
        List<User> res=ManagerService.viewUser();
        if(res==null) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success("查询成功",res);
    }

    @GetMapping(value="/deleteOne")
    public ResultBean deleteOne(@RequestParam String id){
        int res = ManagerService.deleteOne(id);
        if (res==0) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success("删除成功");
    }
}
